let express = require("express");
let qs = require("querystring");
let user = express.Router();
let { pool } = require("../db/pool");
user.get('/user/info',(req,res)=>{
    // console.log(req.query)
    pool.getConnection((err,connection)=>{
        if(err) throw err;
        let sql = `select * from base_user where user_name='${req.query.username}'`
        connection.query(sql,(err,result)=>{
            if(err) throw err;
            // console.log(result)
            res.send(result)
            connection.release()
        })
    })
})
user.get('/user/findById',(req,res)=>{
    // console.log(req.query)
    pool.getConnection((err,connection)=>{
        if(err) throw err;
        let sql = `select user_name,user_face from base_user where user_id='${req.query.user_id}'`
        connection.query(sql,(err,result)=>{
            if(err) throw err;
            // console.log(result)
            res.send(result)
            connection.release()
        })
    })
})
user.get('/user/published',(req,res)=>{
    pool.getConnection((err,connection)=>{
        if(err) throw err;
        let sql = `select * from base_user,dynamic_recent where user_name='${req.query.username}' and dynamic_recent.author_id=base_user.user_id order by create_time desc`
        connection.query(sql,(err,result)=>{
            if(err) throw err;
            // console.log(result)
            res.send(result)
            connection.release() 
        })
    })
})
user.get('/user/findAll',(req,res)=>{
    pool.getConnection((err,connection)=>{
        if(err) throw err;
        let sql = `select * from base_user`
        connection.query(sql,(err,result)=>{
            if(err) throw err;
            res.send(result)
        })
        connection.release();
    })
})
module.exports = {
    user
}